package com.xiaomei.manager.web.controller;

import java.sql.Timestamp;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.xiaomei.manager.model.Complain;
import com.xiaomei.manager.service.IComplainService;
import com.xiaomei.manager.service.ISysUserService;
import com.xiaomei.manager.web.dto.ComplainDto;
import com.xiaomei.manager.web.dto.req.ComplainQueryDto;
import com.xiaomei.manager.web.page.Page;

@Controller
@RequestMapping("/complain")
public class ComplainController {
	@Autowired
	private  IComplainService iComplainServiec;
	
	@RequiresPermissions("complain:view")
	@RequestMapping()
	public String  List(HttpServletRequest request,ComplainQueryDto dto,Page<ComplainDto> page){
		iComplainServiec.selectByParamMap(dto,page);
		request.setAttribute("dto", dto);
		request.setAttribute("page", page);
		return "/complain/list";
	}
	
	@RequiresPermissions("complain:update")
	@RequestMapping(value = "/{id}/update",method = RequestMethod.GET)
	public String detail(@PathVariable("id") Integer id, Model model){
		Complain selectByPrimaryKey = (Complain)iComplainServiec.selectByPrimaryKey(id);
		model.addAttribute("Complain",selectByPrimaryKey);	
		return "/complain/detail";
	}
	@RequiresPermissions("complain:update")
	@RequestMapping(value = "/{id}/update",method = RequestMethod.POST)
	public String update(Complain complain, RedirectAttributes redirectAttributes){
		complain.setHandeTime(new Timestamp(System.currentTimeMillis()));
		iComplainServiec.updateByPrimaryKey(complain);
		redirectAttributes.addFlashAttribute("msg", "修改成功");
		return "redirect:/complain";
	}	
}
